package com.ruoyi.park.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.park.mapper.AdmittanceRecordMapper;
import com.ruoyi.park.domain.AdmittanceRecord;
import com.ruoyi.park.service.IAdmittanceRecordService;

/**
 * 在场车辆Service业务层处理
 * 
 * @author 博雅
 * @date 2023-12-15
 */
@Service
public class AdmittanceRecordServiceImpl implements IAdmittanceRecordService 
{
    @Autowired
    private AdmittanceRecordMapper admittanceRecordMapper;

    /**
     * 查询在场车辆
     * 
     * @param admittanceId 在场车辆主键
     * @return 在场车辆
     */
    @Override
    public AdmittanceRecord selectAdmittanceRecordByAdmittanceId(Long admittanceId)
    {
        return admittanceRecordMapper.selectAdmittanceRecordByAdmittanceId(admittanceId);
    }

    /**
     * 查询在场车辆列表
     * 
     * @param admittanceRecord 在场车辆
     * @return 在场车辆
     */
    @Override
    public List<AdmittanceRecord> selectAdmittanceRecordList(AdmittanceRecord admittanceRecord)
    {
        return admittanceRecordMapper.selectAdmittanceRecordList(admittanceRecord);
    }

    /**
     * 新增在场车辆
     * 
     * @param admittanceRecord 在场车辆
     * @return 结果
     */
    @Override
    public int insertAdmittanceRecord(AdmittanceRecord admittanceRecord)
    {
        return admittanceRecordMapper.insertAdmittanceRecord(admittanceRecord);
    }

    /**
     * 修改在场车辆
     * 
     * @param admittanceRecord 在场车辆
     * @return 结果
     */
    @Override
    public int updateAdmittanceRecord(AdmittanceRecord admittanceRecord)
    {
        return admittanceRecordMapper.updateAdmittanceRecord(admittanceRecord);
    }

    /**
     * 批量删除在场车辆
     * 
     * @param admittanceIds 需要删除的在场车辆主键
     * @return 结果
     */
    @Override
    public int deleteAdmittanceRecordByAdmittanceIds(Long[] admittanceIds)
    {
        return admittanceRecordMapper.deleteAdmittanceRecordByAdmittanceIds(admittanceIds);
    }

    /**
     * 删除在场车辆信息
     * 
     * @param admittanceId 在场车辆主键
     * @return 结果
     */
    @Override
    public int deleteAdmittanceRecordByAdmittanceId(Long admittanceId)
    {
        return admittanceRecordMapper.deleteAdmittanceRecordByAdmittanceId(admittanceId);
    }

    @Override
    public boolean admittanceIsExist(String carNo) {
        //根据车牌查询停车记录
        List<AdmittanceRecord> list=admittanceRecordMapper.getAdmittanceRecordByByCarNo(carNo);
        if(list!=null && list.size()>0){
            AdmittanceRecord admittanceRecord=list.get(0);
            if(admittanceRecord.getLeaveTime()!=null){
                return false;
            }else {
                return true;
            }
        }else{
            return false;
        }
    }

    @Override
    public AdmittanceRecord getAdmittanceRecord(String carNo) {
        //根据车牌查询停车记录
        List<AdmittanceRecord> list=admittanceRecordMapper.getAdmittanceRecordByByCarNo(carNo);
        if(list!=null && list.size()>0){
            //获取最新停车记录
            AdmittanceRecord record=list.get(0);
            if(record.getLeaveTime()==null){//离场时间为空，说明还未出场
                return record;
            }
        }
        return null;
    }
}
